package com.design.patterns.list.visitor;

import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;

/**
 * @author Wangzhiwen
 */
public class ObjectStructure {

    // 元素列表
    private List<Element> elements = new LinkedList<>();

    public void add(Element... elements){
        if (elements != null && elements.length != 0){
            this.elements.addAll(Arrays.asList(elements));
        }
    }

    public void remove(Element element){
        if (element != null){
            elements.remove(element);
        }
    }

    public void clean(){
        this.elements.clear();
    }

    public void operating(Visitor visitor){
        for (Element element : elements) {
            element.accept(visitor);
        }
    }
}
